//
// Decompiled by Jadx - 596ms
//
package gj;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.constraintlayout.widget.i;
import androidx.recyclerview.widget.RecyclerView;
import cc.t;
import com.google.gson.Gson;
import dg.b;
import fi.e;
import fi.p;
import fi.w;
import fj.d;
import fm.c;
import fn.j;
import fn.x;
import fn.y;
import gc.bj;
import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import me.plusne.Adapter.Login.HookSetListAdapter;
import me.plusne.NativeTools;
import me.plusne.common.Json.JsonHookStatic;
import me.plusne.common.Json.JsonSetting;
import me.plusne.common.Json.JsonWebdav;
import me.plusne.common.Json.Login.JsonLoginQuerySet;
import r.f;
import r.g;
import r.h;

public final class k {

    @SuppressLint({"StaticFieldLeak"})
    public static w a;
    public static JsonWebdav b;

    @SuppressLint({"StaticFieldLeak"})
    public static w c;
    public final Activity d;
    public t e;
    public HookSetListAdapter f;
    public boolean g = true;

    @SuppressLint({"SetTextI18n"})
    public k(Activity activity) {
        AlertDialog alertDialog;
        this.d = activity;
        if (x.bt < 1) {
            return;
        }
        w wVar = a;
        if (wVar != null && (alertDialog = wVar.c) != null && alertDialog.isShowing()) {
            return;
        }
        j.z(activity);
        if (y.by.getUserInfo() == null) {
            new d(activity, new g(this, 0));
        } else {
            j();
        }
    }

    public static void h(k kVar) {
        StringBuilder sb;
        String str;
        f fVar;
        String str2;
        kVar.getClass();
        b bVar = new b();
        bVar.f(b.getData().getYun_user(), b.getData().getYun_pass());
        if (b.getData().getYun_host().endsWith("/")) {
            sb = new StringBuilder();
            sb.append(b.getData().getYun_host());
            str = "PlusNE/";
        } else {
            sb = new StringBuilder();
            sb.append(b.getData().getYun_host());
            str = "/PlusNE/";
        }
        sb.append(str);
        JsonHookStatic jsonHookStatic = y.by;
        sb.append(jsonHookStatic.getAppName());
        String x = androidx.activity.b.x(sb.toString(), "/PlusNE_setting.pn");
        StringBuilder sb2 = new StringBuilder();
        Activity activity = kVar.d;
        sb2.append(activity.getCacheDir());
        sb2.append("/PlusNE_");
        sb2.append(jsonHookStatic.getPre());
        sb2.append(System.currentTimeMillis());
        sb2.append(".ne");
        String sb3 = sb2.toString();
        try {
            fi.y.e(activity);
            if (!bVar.c(x)) {
                fVar = new f(activity);
                fVar.j();
                str2 = "恢复失败,没有可恢复的设置项";
            } else if (d.f(bVar.d(x), sb3)) {
                JsonSetting jsonSetting = (JsonSetting) new Gson().fromJson(d.e(sb3), JsonSetting.class);
                if (jsonSetting != null && !TextUtils.isEmpty(jsonSetting.getSign())) {
                    List<c> list = (List) new Gson().fromJson(jsonSetting.getSetting(), new s().getType());
                    if (list != null && !list.isEmpty()) {
                        if (!NativeTools.k(new Gson().toJson(list)).equals(jsonSetting.getSign())) {
                            fVar = new f(activity);
                            fVar.d = 80;
                            fVar.j();
                            str2 = "导入失败,数据损坏";
                        } else {
                            jsonHookStatic.getDb().q.r();
                            for (c cVar : list) {
                                c cVar2 = new c();
                                cVar2.b = cVar.b;
                                cVar2.c = cVar.c;
                                cVar2.d = cVar.d;
                                y.by.getDb().q.t(cVar2);
                            }
                            fVar = new f(activity);
                            fVar.d = 80;
                            fVar.n();
                            str2 = "成功导入 " + list.size() + " 条设置!";
                        }
                    }
                    fVar = new f(activity);
                    fVar.d = 80;
                    fVar.j();
                    str2 = "导入失败,没有数据";
                }
                fVar = new f(activity);
                fVar.j();
                str2 = "导入失败,数据解析错误";
            } else {
                fi.y.d();
                f fVar2 = new f(activity);
                fVar2.j();
                fVar2.l("恢复失败,读取云端配置失败");
                return;
            }
            fVar.l(str2);
            fi.y.d();
        } catch (IOException | IllegalArgumentException e) {
            fi.y.d();
            e.printStackTrace();
            f fVar3 = new f(activity);
            fVar3.j();
            fVar3.l("请检查参数是否填写正确:" + e.getMessage());
        }
    }

    public final void i() {
        fi.b bVar = new fi.b();
        bVar.b("设置webdav信息");
        bVar.b("云备份");
        bVar.b("云恢复");
        bVar.b("帮助文档");
        w wVar = new w(this.d, e.LIST_ITEM);
        wVar.aj = "备份与恢复";
        wVar.bb();
        wVar.u = false;
        wVar.bb();
        wVar.t = false;
        wVar.bb();
        wVar.ay(bVar);
        wVar.ae = new g(this, 8);
        wVar.bk();
    }

    public final void j() {
        JsonLoginQuerySet jsonLoginQuerySet = (JsonLoginQuerySet) new Gson().fromJson(fn.b.i("LoginQuerySet"), JsonLoginQuerySet.class);
        if (jsonLoginQuerySet != null) {
            int toDay = jsonLoginQuerySet.getToDay();
            Date date = h.a;
            if (toDay == Calendar.getInstance().get(7)) {
                k(jsonLoginQuerySet);
                return;
            }
        }
        new f(this.d, new g(this, 1));
    }

    @SuppressLint({"SetTextI18n", "NotifyDataSetChanged"})
    public final void k(JsonLoginQuerySet jsonLoginQuerySet) {
        JsonHookStatic jsonHookStatic = y.by;
        if (jsonHookStatic.getUserInfo() == null) {
            return;
        }
        Activity activity = this.d;
        View inflate = LayoutInflater.from(activity).inflate(-2113142702, (ViewGroup) null, false);
        int i = 0x7f820045;
        LinearLayout linearLayout = (LinearLayout) i.cg(0x7f820045, inflate);
        if (linearLayout != null) {
            i = 0x7f8200de;
            ImageView imageView = (ImageView) i.cg(0x7f8200de, inflate);
            if (imageView != null) {
                i = 0x7f8200e0;
                ImageView imageView2 = (ImageView) i.cg(0x7f8200e0, inflate);
                if (imageView2 != null) {
                    i = 0x7f8200ee;
                    EditText editText = (EditText) i.cg(0x7f8200ee, inflate);
                    if (editText != null) {
                        i = 0x7f820112;
                        ImageView imageView3 = (ImageView) i.cg(0x7f820112, inflate);
                        if (imageView3 != null) {
                            i = 0x7f820166;
                            ImageView imageView4 = (ImageView) i.cg(0x7f820166, inflate);
                            if (imageView4 != null) {
                                i = 0x7f8201ff;
                                TextView textView = (TextView) i.cg(0x7f8201ff, inflate);
                                if (textView != null) {
                                    i = 0x7f820219;
                                    TextView textView2 = (TextView) i.cg(0x7f820219, inflate);
                                    if (textView2 != null) {
                                        i = 0x7f82021a;
                                        ImageView imageView5 = (ImageView) i.cg(0x7f82021a, inflate);
                                        if (imageView5 != null) {
                                            i = 0x7f82021b;
                                            LinearLayout linearLayout2 = (LinearLayout) i.cg(0x7f82021b, inflate);
                                            if (linearLayout2 != null) {
                                                i = 0x7f82021e;
                                                TextView textView3 = (TextView) i.cg(0x7f82021e, inflate);
                                                if (textView3 != null) {
                                                    this.e = new t((LinearLayout) inflate, linearLayout, imageView, imageView2, editText, imageView3, imageView4, textView, textView2, imageView5, linearLayout2, textView3);
                                                    w wVar = new w(activity);
                                                    wVar.bj(fi.e.VIEW);
                                                    wVar.ar = this.e.a;
                                                    wVar.bk();
                                                    a = wVar;
                                                    wVar.c.setOnKeyListener(new h(this));
                                                    a.c.setOnDismissListener(new fp.h(7));
                                                    this.e.h.setText(jsonHookStatic.getAppName() + "(" + jsonHookStatic.getVersionName() + ")");
                                                    this.e.f.setOnLongClickListener(new bj(3, this));
                                                    g.v(this.e.d, -2113535894);
                                                    g.v(this.e.j, -2113535894);
                                                    g.v(this.e.g, -2113535894);
                                                    g.v(this.e.c, -2113535894);
                                                    r.e.d(-2113535896, 20.0f, this.e.k);
                                                    jsonHookStatic.setMenuCall("自动关闭App", new g(this, 2));
                                                    if (jsonHookStatic.getMenuCall() != null) {
                                                        jsonLoginQuerySet.getGroup().addAll(jsonHookStatic.getMenuCall());
                                                    }
                                                    this.f = new HookSetListAdapter(activity, jsonLoginQuerySet);
                                                    View a2 = fi.x.a(activity, 0, 0, 0, 0);
                                                    a2.setItemAnimator((RecyclerView.m) null);
                                                    r.e.d(-2113535896, 20.0f, a2);
                                                    a2.setAdapter(this.f);
                                                    this.e.b.addView(a2);
                                                    this.e.i.setText(jsonHookStatic.getUserInfo().getName());
                                                    this.e.l.setGravity(17);
                                                    this.e.l.setText("@" + jsonHookStatic.getMainVersionName() + "(" + jsonHookStatic.getMainVersionCode() + ")");
                                                    f y = androidx.activity.b.y(activity);
                                                    y.d = 80;
                                                    y.l("云端数据:" + jsonLoginQuerySet.getCode() + " 本地版本:" + jsonHookStatic.getVersionCode());
                                                    LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) this.e.b.getLayoutParams();
                                                    layoutParams.weight = 0.0f;
                                                    r.e.d(-2113535899, 15.0f, this.e.e);
                                                    this.e.b.setLayoutParams(layoutParams);
                                                    this.e.e.setPadding(0, 0, 0, 0);
                                                    this.e.c.setOnClickListener(new i(this, 0));
                                                    this.e.e.setImeOptions(6);
                                                    this.e.e.setOnEditorActionListener(new p(4, this));
                                                    this.e.e.addTextChangedListener(new b(this));
                                                    this.e.k.setOnClickListener(new i(this, 1));
                                                    this.e.d.setOnClickListener(new i(this, 2));
                                                    return;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        throw new NullPointerException("Missing required view with ID: ".concat(inflate.getResources().getResourceName(i)));
    }
}
